package com.example.temp.controller;

import cn.hutool.core.collection.CollUtil;
import com.example.temp.common.Result;
import com.example.temp.entity.AssetInformation;
import com.example.temp.entity.AssetLend;
import com.example.temp.entity.AssetMaintain;
import com.example.temp.entity.SysUser;
import com.example.temp.service.AssetInformationService;
import com.example.temp.service.AssetLendService;
import com.example.temp.service.AssetMaintainService;
import com.example.temp.service.SysUserService;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 首页看板echarts
 */
@Tag(name = "首页看板echarts")
@RestController
@RequestMapping("/echarts")
public class EchartsController {

    @Autowired
    private AssetInformationService assetInformationService;

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private AssetLendService assetLendService;

    @Autowired
    private AssetMaintainService assetMaintainService;

    /**
     * 资产状态
     * @return
     */
    @Operation(summary = "资产状态")
    @GetMapping("/states")
    private Result AssetState(){
        List<AssetInformation> informations =assetInformationService.list();
        int normal = 0;
        int lend=0;
        int maintain=0;
        int bad=0;
        for (AssetInformation asset:informations){
            String assetState = asset.getAssetState();
            if(assetState.equals("正常")){
                normal++;
            }else if(assetState.equals("借出")){
                lend++;
            }else if(assetState.equals("维修")){
                maintain++;
            }else {
                bad++;
            }
        }
        return Result.success(CollUtil.newArrayList(normal,lend,maintain,bad));
    }

    /**
     * 用户性别比例
     * @return
     */
    @Operation(summary = "用户性别比例")
    @GetMapping("/sex")
    private Result UserSex(){
        List<SysUser> informations =sysUserService.list();
        int male = 0;
        int female=0;
        int unknwon=0;
        for (SysUser user:informations){
            String sex = user.getSex();
            if(sex.equals("0")){
                male++;
            }else if(sex.equals("1")){
                female++;
            }else {
                unknwon++;
            }
        }
        return Result.success(CollUtil.newArrayList(male,female,unknwon));
    }

    /**
     * 借出计数
     * @return
     */
    @Operation(summary = "借出计数")
    @GetMapping("/lendcount")
    private Result LendCount(){
        return Result.success(assetLendService.CountLend());
    }

    /**
     * 资产总价
     * @return
     */
    @Operation(summary = "资产总价")
    @GetMapping("/assetmoney")
    public Result AssetMoney(){
        return Result.success(assetInformationService.AssetMoney());
    }

    /**
     * 资产总数
     * @return
     */
    @Operation(summary = "资产总数")
    @GetMapping("/assetcount")
    public Result AssetCount(){
        return Result.success(assetInformationService.AssetCount());
    }
    /**
     * 维修总数
     * @return
     */
    @Operation(summary = "维修总数")
    @GetMapping("/maintaincount")
    public Result MaintainCount(){
        return Result.success(assetMaintainService.maintainCount());
    }


}
